package com.dengbw.systemtransfer.service;

import com.dengbw.systemtransfer.mapper.SysConfigMapper;
import com.dengbw.systemtransfer.model.db.SysConfig;
import com.dengbw.systemtransfer.model.function.Task;
import com.dengbw.systemtransfer.model.request.CunInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author dengbw
 * @date 2021/11/11 2:50 下午
 */
@Service
public class SysConfigService {

    SysConfigMapper sysConfigMapper;

    @Autowired
    public SysConfigService(SysConfigMapper sysConfigMapper) {
        this.sysConfigMapper = sysConfigMapper;
    }

    @Transactional(rollbackFor = Exception.class)
    public void saveSysConfig(String zhenCorpId, CunInfo cunInfo) {
        Task.sysConfigTask(cunInfo).forEach(s -> sysConfigMapper.save(s.getLabelId(), s.getConfigName(), s.getConfigKey(), s.getConfigValue(), s.getValueType(), zhenCorpId, cunInfo.getSubIdInZhen()));
    }
}
